/* 
 *  <copyright file="FactoryBuilder.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Reflection;

using SobrietyEngine.Common;

namespace SobrietyEngine.Components
{
    public class ComponentFactoryBuilder<T>:IFactoryBuilder<SobrietyEngine.Components.IComponent>
    {
        String type;
        
        public ComponentFactoryBuilder(String _type)
        {
            type = _type;
        }

        public ComponentFactoryBuilder()
        {
            type = typeof(T).ToString();
        }

        public SobrietyEngine.Components.IComponent Build(Parameters parms)
        {
            /*
            ConstructorInfo ci = typeof(T).GetConstructor(new Type[1] { typeof(Parameters) });
            return ci.Invoke(new object[1] {parms}) as SobrietyEngine.Components.IComponent;*/
            ConstructorInfo ci = typeof(T).GetConstructor(new Type[] {});
            SobrietyEngine.Components.IComponent cmp =  ci.Invoke(new object[]{}) as SobrietyEngine.Components.IComponent;
            cmp.Set(parms);
            return cmp;
            
        }

        public SobrietyEngine.Components.IComponent Build()
        {
            ConstructorInfo ci = typeof(T).GetConstructor(new Type[] { });
            SobrietyEngine.Components.IComponent cmp = ci.Invoke(new object[] { }) as SobrietyEngine.Components.IComponent;
            return cmp;

        }

        public new string GetType()
        {
            return type;
        }
    }
}